# 存储订单文件
import sys
sys.path.append("..")
import json
from flask import request
from create_id import get_id
from db_client import *

def store_order_file():
    # 存储订单文件
    token = request.headers.get('token')
    flag, right = token_client.check_token(token)
    if not flag:
        t = {
            'state': 'false',
            'msg': '存储订单文件失败'
        }
        return json.dumps(t, ensure_ascii=False)
    else:
        data = json.loads(request.get_data())
        content = data['content']
        order_id = data['order_id']
        create_date = data['create_date']

        _id = get_id('DW')
        flag2 = mysql_client.store_order_file(_id, order_id, content, create_date)
        if flag2:
            t = {
                'state': 'true',
                'msg': 'success'
            }
            return json.dumps(t, ensure_ascii=False)
        else:
            t = {
                'state': 'false',
                'msg': '提交订单文件失败，稍后再试。'
            }
            return json.dumps(t, ensure_ascii=False)